<template>
  <el-dropdown trigger="click" class='international' @command="handleSetLanguage">
    <span class="el-dropdown-link" style="font-weight: 700;">
    {{dropDownSize}}<i class="el-icon-arrow-down el-icon--right"></i>
  </span>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="zh-CN">中文</el-dropdown-item>
      <el-dropdown-item command="en-US">English</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import Cookies from 'js-cookie'
export default {
  data() {
    return {
      dropDownSize: '中文'
    }
  },
  computed: {
    language() {
      return this.$store.getters.language
    }
  },
  mounted() {
    if (localStorage.getItem('language') === 'zh-CN') {
      this.dropDownSize = '中文'
    } else {
      this.dropDownSize = 'English'
    }
  },
  methods: {
    handleSetLanguage(lang) {
      console.log(lang)
      if (lang === 'zh-CN') {
        this.dropDownSize = '中文'
      } else {
        this.dropDownSize = 'English'
      }
      this.$i18n.locale = lang
      this.$store.dispatch('setLanguage', lang)
      this.$message({
        message: '切换语言成功',
        type: 'success'
      })
    }
  }
}
</script>

<style scoped>
.international-icon {
  font-size: 20px;
  cursor: pointer;
  vertical-align: -5px!important;
}
</style>


